package com.br.rh.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.br.rh.vo.Contato;
import java.sql.Connection;
import java.sql.PreparedStatement;

public class ContatoDAO extends DataUtils{
	public List<Contato> getAll(){
		Connection conn = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		Contato contato = null;
		ArrayList<Contato> lista = new ArrayList<Contato>();
		try {
			conn = getConnection();
			stmt = conn.prepareStatement("SELECT * FROM contato");
			rs = stmt.executeQuery();
			while(rs.next()){
				contato = new Contato();
				contato.setCodigo(rs.getInt(1));
				contato.setCelular(rs.getString((2)));
				contato.setEmail(rs.getString(3));
				contato.setTelefone(rs.getString(4));
				lista.add(contato);
			}
			conn.close();
			stmt.close();
			rs.close();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return lista;
	}
}
